﻿/*
' Copyright (c) 2014 Christoc.com
'  All rights reserved.
' 
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
' DEALINGS IN THE SOFTWARE.
' 
*/

using System.Linq;
using DotNetNuke.Data;

namespace CkSoftware.GroupMeChatModule.Components
{
	public class PermanentGroupMeLogonsController
	{
		public void CreateItem(PermanentGroupMeLogon t)
		{
			using (IDataContext ctx = DataContext.Instance())
			{
				var rep = ctx.GetRepository<PermanentGroupMeLogon>();
				rep.Insert(t);
			}
		}

		public void DeleteItem(int userId)
		{
			var t = GetItem(userId);
			DeleteItem(t);
		}

		public void DeleteItem(PermanentGroupMeLogon t)
		{
			using (IDataContext ctx = DataContext.Instance())
			{
				var rep = ctx.GetRepository<PermanentGroupMeLogon>();
				rep.Delete(t);
			}
		}

		public PermanentGroupMeLogon GetItem(int userId)
		{
			PermanentGroupMeLogon t;
			using (IDataContext ctx = DataContext.Instance())
			{
				var rep = ctx.GetRepository<PermanentGroupMeLogon>();
				t = rep.Find("WHERE UserId = @0", userId).SingleOrDefault();
			}
			return t;
		}

		public void UpdateItem(PermanentGroupMeLogon t)
		{
			using (IDataContext ctx = DataContext.Instance())
			{
				var rep = ctx.GetRepository<PermanentGroupMeLogon>();
				rep.Update(t);
			}
		}

	}
}
